import { NTabPane, type TabPaneProps } from "naive-ui";
import type { HTMLAttributes } from "vue";
import { getSlotsDom } from "../utils";
import type { BaseComponentType } from "../types";
export type OmitTabPaneProps<K extends keyof TabPaneProps> = Omit<
  TabPaneProps,
  K
>;

export type TabPaneFactoryConstructorType = {
  attrs?: HTMLAttributes;
  props?: OmitTabPaneProps<"name"> & { name: string | number };
  name: string | number;
  defaultSlot?: BaseComponentType;
  tabSlot?: BaseComponentType;
}
export class TabPaneFactory {
  private attrs: HTMLAttributes = {};
  private props: OmitTabPaneProps<"name"> & { name: string | number } = {
    name: "",
  };
  private defaultSlot: BaseComponentType = null;
  private tabSlot: BaseComponentType = null;

  constructor(data?: TabPaneFactoryConstructorType) {
    if (data?.attrs) this.setAttrs(data.attrs);
    if (data?.props) this.setProps(data.props);
    if (data?.defaultSlot) this.setDefault(data.defaultSlot);
    if (data?.tabSlot) this.setTab(data.tabSlot);
  }

  setAttrs(attrs: HTMLAttributes) {
    this.attrs = attrs;
    return this
  }

  setProps(props: OmitTabPaneProps<"name"> & { name: string | number }) {
    this.props = props;
    return this;
  }

  setDefault(defaultSlot: BaseComponentType) {
    this.defaultSlot = defaultSlot;
    return this;
  }

  setTab(tabSlot: BaseComponentType) {
    this.tabSlot = tabSlot;
    return this;
  }



  create() {
    return (
      <NTabPane {...this.attrs} {...this.props}>
        {{
          default:
            this.defaultSlot != null
              ? () => getSlotsDom(this.defaultSlot)
              : null,
          tab: this.tabSlot != null ? () => getSlotsDom(this.tabSlot) : null,
        }}
      </NTabPane>
    );
  }
}
